import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author ：hzs
 * @date ：Created in 2020/12/29 15:30
 * @description：
 * @modified By：
 * @version: $
 */
public class LRU extends LinkedHashMap {

    private int capacity;

    public LRU(int capacity) {
        super(capacity, 1.0F, true);
        this.capacity = capacity;
    }

    public int get(int key) {
        return (int)super.getOrDefault(key, -1);
    }

    public void put(int key, int value) {
        super.put(key, value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return super.size() > capacity;
    }
}
